package com.ruoyi.web.controller.productionre;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.production.domain.SeedReturn;
import com.ruoyi.production.domain.SimpleProduction;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.production.domain.StromaReturn;
import com.ruoyi.production.service.IStromaReturnService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 基质退回Controller
 *
 * @author ruoyi
 * @date 2021-07-16
 */
@Api("基质退回")
@RestController
@RequestMapping("/production/stromare")
public class StromaReturnController extends BaseController
{
    @Autowired
    private IStromaReturnService stromaReturnService;

    /**
     * 查询基质退回列表
     */
    @ApiOperation("查询基质退回列表")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:stromare:list')")
    @GetMapping("/list")
    public TableDataInfo list(StromaReturn stromaReturn)
    {
        startPage();
        List<StromaReturn> list = stromaReturnService.selectStromaReturnList(stromaReturn);
        return getDataTable(list);
    }

    /**
     * 导出基质退回列表
     */
    @ApiOperation("导出基质退回列表")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:stromare:export')")
    @Log(title = "基质退回", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(StromaReturn stromaReturn)
    {
        List<StromaReturn> list=new ArrayList();
        //通过id来取
        Long a[]=stromaReturn.getStromaReturnIds();
        for(int i=0;i<a.length;i++) {
            StromaReturn list1 = stromaReturnService.selectStromaReturnById(a[i]);
            list.add(list1);
        }


        ExcelUtil<StromaReturn> util = new ExcelUtil<StromaReturn>(StromaReturn.class);
        return util.exportExcel(list, "基质退回数据");
    }

    /**
     * 获取基质退回详细信息
     */
    @ApiOperation("获取基质退回详细信息")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:stromare:query')")
    @GetMapping(value = "/{stromaReturnId}")
    public AjaxResult getInfo(@PathVariable("stromaReturnId") Long stromaReturnId)
    {
        return AjaxResult.success(stromaReturnService.selectStromaReturnById(stromaReturnId));
    }

    /**
     * 新增基质退回
     */
    @ApiOperation("新增基质退回")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:stromare:add')")
    @Log(title = "基质退回", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StromaReturn stromaReturn)
    {
        return toAjax(stromaReturnService.insertStromaReturn(stromaReturn));
    }

    /**
     * 修改基质退回
     */
    @ApiOperation("修改基质退回")
    @ResponseBody
    @PreAuthorize("@ss.hasAnyPermi('production:stromare:edit,production:stromare:permit')")
    @Log(title = "基质退回", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StromaReturn stromaReturn)
    {
        return toAjax(stromaReturnService.updateStromaReturn(stromaReturn));
    }

    /**
     * 删除基质退回
     */
    @ApiOperation("删除基质退回")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:stromare:remove')")
    @Log(title = "基质退回", businessType = BusinessType.DELETE)
	@DeleteMapping("/{stromaReturnIds}")
    public AjaxResult remove(@PathVariable Long[] stromaReturnIds)
    {
        return toAjax(stromaReturnService.deleteStromaReturnByIds(stromaReturnIds));
    }

    /**
     * 获取基质种类下拉框
     */
    @ApiOperation("获取基质种类下拉框")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:stromare:stromakind')")
    @GetMapping("/stromakind")
    public TableDataInfo getStromaKind(){

        List<StromaReturn> list = stromaReturnService.getStromaKind();
        List<SimpleProduction> simpleProductions = new ArrayList<>();
        for (StromaReturn stromaReturn:list) {
            Long id = stromaReturn.getStromaKindId();
            String name = stromaReturn.getStromaKind();
            SimpleProduction simpleProduction = new SimpleProduction(id,name);
            simpleProductions.add(simpleProduction);
        }
        return getDataTable(simpleProductions);
    }

    /**
     * 获取基质类型下拉框
     */
    @ApiOperation("获取基质类型下拉框")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:stromare:stromatype')")
    @GetMapping("/stromatype")
    public TableDataInfo getStromaType(){

        List<StromaReturn> list = stromaReturnService.getStromaTypeName();
        List<SimpleProduction> simpleProductions = new ArrayList<>();
        for (StromaReturn stromaReturn:list) {
            Long id = stromaReturn.getStromaTypeId();
            String name = stromaReturn.getStromaTypeName();
            SimpleProduction simpleProduction = new SimpleProduction(id,name);
            simpleProductions.add(simpleProduction);
        }
        return getDataTable(simpleProductions);
    }

    /**
     * 获取用户列表下拉框
     */
    @ApiOperation("获取用户列表下拉框")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:stromare:username')")
    @GetMapping("/username")
    public TableDataInfo getUserName(){

        List<StromaReturn> list = stromaReturnService.getUserName();
        List<SimpleProduction> simpleProductions = new ArrayList<>();
        for (StromaReturn stromaReturn:list) {
            Long id = stromaReturn.getUserId();
            String name = stromaReturn.getUserName();
            SimpleProduction simpleProduction = new SimpleProduction(id,name);
            simpleProductions.add(simpleProduction);
        }
        return getDataTable(simpleProductions);
    }

    /**
     * 获取品牌下拉框
     */
    @ApiOperation("获取品牌下拉框")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:stromare:brand')")
    @GetMapping("/brand/{stromaTypeId}")
    public TableDataInfo getBrand(@PathVariable("stromaTypeId") Long stromaTypeId){

        List<String> list = stromaReturnService.getBrand(stromaTypeId);
        return getDataTable(list);
    }

    /**
     * 获取公司列表下拉框
     */
    @ApiOperation("获取公司列表下拉框")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:stromare:origincompany')")
    @GetMapping("/origincompany/{stromaTypeId}")
    public TableDataInfo getOriginCompany(@PathVariable("stromaTypeId") Long stromaTypeId){

        List<String> list = stromaReturnService.getOriginCompany(stromaTypeId);
        return getDataTable(list);
    }
}
